import { h } from "koishi"

export const name = "global-censor"

export const inject = ["censor"]

export function apply(ctx) {
  ctx.on("before-send", async session => {
    const before = h("", session.elements).toString(true)
    session.elements = await ctx.censor.transform(session.elements, session)
    const after = h("", session.elements).toString(true)
    if (~~after.match(/\*/g)?.length - ~~before.match(/\*/g)?.length > Math.max(4, before.length / 30)) session.content = "不好意思，我走神了，换个话题聊聊吧"
  }, true)
}
